package no.sachmuld.methodcombination.examples.adapter.closstandardstyle;

import no.sachmuld.methodcombination.api.BehaviourChain;
import no.sachmuld.methodcombination.api.adapter.Standard;
import no.sachmuld.methodcombination.api.MethodInvocation;

/**
 *
 */
public abstract class Foo {

    private BehaviourChain<FooBehaviour> chain = new BehaviourChain<>();

    final public String bar(final int i) {
        return new Standard<FooBehaviour, String>(chain) {

            @Override
            protected String executeAround(FooBehaviour behaviour, MethodInvocation<String> methodInvocation) {
                return behaviour.aroundBar(i, methodInvocation);
            }

            @Override
            protected void executeBefore(FooBehaviour behaviour) {
                behaviour.beforeBar(i);
            }

            @Override
            protected String executePrimary(FooBehaviour behaviour, MethodInvocation<String> methodInvocation) {
                return behaviour.bar(i, methodInvocation);
            }

            @Override
            protected void executeAfter(FooBehaviour behaviour) {
                behaviour.afterBar(i);
            }
        }.execute();
    }

    final protected Foo with(FooBehaviour... fooBehaviours) {
        chain.addAll(fooBehaviours);
        return this;
    }


}
